var rootPath = getRootPath();
var click_flag = false;
var isPhone = isPhoneScreen();

$(function() {
	//1.密码输入时，去除所有的错误控制信息
	$("#password").focus(function() {
		hideMsg();
	});
	
	//2.密码框有值的情况，下一步按钮显示正常
	$("#password").bind('input propertychange', function() {
		if($("#password").val() == '') {
			$("#next").css({"background-color":"#bbbbbb","cursor":"default"});
			$("#next").attr("disabled",true);
		} else {
			$("#next").css({"background-color":"rgb(197,24,10)","cursor":"pointer"});
			$("#next").attr("disabled",false);			
		}
	});
	
	$("#password").keyup(function(event) {
		event.stopPropagation();
		if(event.keyCode == 13) {
			$("#next").click();
		}
	});
	
	//忘记密码
	$("#fPwd").click(function() {
		parent.$("#content").prop("src","modifyPwdByPhoneOrEmail.html");
	});
	
	//下一步
	$("#next").click(function() {
		var password = $("#password").val();
		if(password == "") {
			showErrMsg("原密码不能为空");
			return;
		}
		
		$.ajax({
			url: rootPath + '/login/checkPassword',
			type: 'GET',
			data: {
				"password" : password
			},
			success: function(data) {
				if("true" == data) {
					parent.$("#content").prop("src","setNewPwd.html");						
				} else {
					showErrMsg("原密码错误,请重新输入");
				}
			},
			error: function (jqXHR, textStatus, errorThrown) {
				layer.alert("error");
			}
		});
	});
});

function showErrMsg(msg){
	if(msg != ''){
		$("#password_msg").text(msg);
		$(".msg").show();
	}
}

function hideMsg() {
	$("#password_msg").text("");
	$(".msg").hide();
}